package com.by.yz.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.by.yz.R;
import com.by.yz.activity.Famous_doctor_detail;
import com.by.yz.entity.TechnologyTeam1;

import java.util.List;

/**
 * Created by mrs yang on 2016/10/30.
 */
public class SeachDoctorAdapter extends RecyclerView.Adapter<SeachDoctorAdapter.ViewHolder> {
    private final TypedValue mTypedValue = new TypedValue();
    private int mBackground;
    private List<TechnologyTeam1> mValues;



    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TechnologyTeam1 tt;

        public final View mView;
        public final ImageView mImageView;
        public final TextView doctorName;
        public final TextView textHospital;
        public final TextView department;
//            public final TextView instruc;
//            public final TextView doctorPosition;


        public ViewHolder(View view) {
            super(view);
            mView = view;
            mImageView = (ImageView) view.findViewById(R.id.avatar);
            doctorName = (TextView) view.findViewById(R.id.doctorName);
            textHospital = (TextView) view.findViewById(R.id.textHospital);
            department = (TextView) view.findViewById(R.id.department);//隶属科室
//                instruc =(TextView) view.findViewById(R.id.textSubDescripting);
//                doctorPosition=(TextView)view.findViewById(R.id.doctorPosition);
        }

//            @Override
//            public String toString() {
//                return super.toString() + " '" + mTextView.getText();
//            }
    }

    public TechnologyTeam1 getValueAt(int position) {
        return mValues.get(position);
    }

    public SeachDoctorAdapter(Context context, List<TechnologyTeam1> items) {
        context.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true);
        mBackground = mTypedValue.resourceId;
        mValues = items;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.home_page_list_item, parent, false);
        // view.setBackgroundResource(mBackground);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        holder.tt = mValues.get(position);
        holder.doctorName.setText(mValues.get(position).getTeamName());
        holder.textHospital.setText(mValues.get(position).getGoodAt());
        holder.department.setText(mValues.get(position).getLocate());
//            holder.instruc.setText(mValues.get(position).getInstruc());
//            holder.doctorPosition.setText(mValues.get(position).getdoctorPosition());


        holder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Context context = v.getContext();
                Intent intent = new Intent(context, Famous_doctor_detail.class);
//                    intent.putExtra(CheeseDetailActivity.EXTRA_NAME, holder.mBoundString);
                Bundle bundle = new Bundle();
                bundle.putSerializable("Doctor",holder.tt);
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });

        Glide.with(holder.mImageView.getContext())
                .load(mValues.get(position).getmImageView())
                .fitCenter()
                .into(holder.mImageView);
    }

    @Override
    public int getItemCount() {
        return mValues.size();
    }
}
